//
//  WillBeShownCollectionViewController.m
//  代号：47
//
//  Created by lanou3g on 15/7/2.
//  Copyright (c) 2015年 杨佩璋. All rights reserved.
//

#import "WillBeShownCollectionViewController.h"
#import "WillBeShownCollectionViewCell.h"
#import "WillBeShownDataViewController.h"
#import "WillBeShownModel.h"
#import "LORefresh.h"

@interface WillBeShownCollectionViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>

@property(nonatomic,retain)UICollectionView *collectionView;

@end

@implementation WillBeShownCollectionViewController
-(void)dealloc{
    
    
    _collectionView = nil;
    [super dealloc];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self createCollection];
    UIImage *image1 = [UIImage imageNamed:@"96-book.png"];
    UIImage *new = [image1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:new style:(UIBarButtonItemStylePlain) target:self action:@selector(createSlideimageView)];
    self.view.backgroundColor = [UIColor whiteColor];
}









-(void)createSlideimageView{

    [self.navigationController popViewControllerAnimated:NO];

}

#pragma mark----------创建collectionView-------
-(void)createCollection{
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init] ;
    flowLayout.minimumInteritemSpacing = 10;
    flowLayout.minimumLineSpacing = 10;
    flowLayout.itemSize = CGSizeMake((kScreen_width - 40)/3, (kScreen_height-50)/4);
    flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:flowLayout];
    [flowLayout release];
    self.collectionView = [[[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:flowLayout] autorelease];
    
    _collectionView.dataSource = self;
    _collectionView.delegate = self;
    _collectionView.backgroundColor = [UIColor whiteColor];
    [_collectionView registerClass:[WillBeShownCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    [self.view addSubview:_collectionView];
    
    [_collectionView addRefreshWithRefreshViewType:LORefreshViewTypeHeaderGif refreshingBlock:^{
        [_collectionView reloadData];
        [_collectionView.gifHeader endRefreshing];
    }];
    
    [flowLayout release];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _arrayCZ.count;
    
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    WillBeShownCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.model = _arrayCZ[indexPath.row];
    cell.backgroundColor = RandomColor;
    return cell;
    
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    WillBeShownDataViewController *willBeShownDataVC = [[WillBeShownDataViewController alloc] init];
    WillBeShownModel *model;
    model = _arrayCZ[indexPath.row];
    willBeShownDataVC.str = model.ID;
    [self.navigationController pushViewController:willBeShownDataVC animated:YES];
    [willBeShownDataVC release];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
